package com.twu.biblioteca.service;

import com.twu.biblioteca.model.bookModel;
import com.twu.biblioteca.model.user;

import java.io.InputStream;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: st
 * Date: 14-4-17
 * Time: 下午3:09
 * To change this template use File | Settings | File Templates.
 */
public class returnBook {

    public String returnBookInfo(InputStream in){
        System.out.println("\n Please enter book name.");
        Scanner sc = new Scanner(in);
        String bookName = sc.nextLine();
        return bookName;
    }

    public bookModel[] return_book(bookModel[] bookList,String bookNameEnter,int customerLen,user[] userList){
        int len = 0;
        boolean exit=false;
        while (len<bookList.length&&bookList[len]!=null) {
            if (bookList[len].getBookName().equals(bookNameEnter)&&bookList[len].getCheckStatus())
            {
                bookList[len].setCheckStatusFalse();
                userList[customerLen].setBook("");
                System.out.println("Thank you for returning the book.");
                exit=true;
                break;
            }
            len++;
        }
        if (!exit)
            System.out.println("That is not a valid book to return.");

        return bookList;
    }
}
